/**
 * Copyright 2007-2008. Chongqing First Information & Network Co., Ltd. All
 * rights reserved. <a>http://www.cqfirst.com.cn</a>
 */
package com.cqcis.uip.base.framework.handlers.impl;

import java.util.List;

import com.cqcis.uip.base.framework.common.Role;
import com.cqcis.uip.base.framework.common.Task;
import com.cqcis.uip.base.framework.core.RegisteredServiceContext;
import com.cqcis.uip.base.framework.core.Service;
import com.cqcis.uip.base.framework.core.ServiceRole;
import com.cqcis.uip.base.framework.core.ServiceRoleIgnore;
import com.cqcis.uip.base.framework.handlers.TableDispatchService;
import com.cqcis.uip.base.framework.handlers.common.AbstractDispatchHandler;


/**
 * @author huangmy
 * @date   2007-12-20
 */
@ServiceRoleIgnore
public class DefaultDispatchHandler extends AbstractDispatchHandler {
	private TableDispatchService service;
	
    public void start(RegisteredServiceContext serviceContext) throws Exception {
    	if (service == null) {
    		throw new NullPointerException("'service' can't be null.");
    	}
    	
    	super.start(serviceContext);
    	
    	if (service instanceof Service) {
			((Service) service).start(serviceContext);
		}
	}
	
	public void stop(RegisteredServiceContext serviceContext) throws Exception {
		if (service instanceof Service) {
			((Service)service).stop(serviceContext);
		}	
		
		super.stop(serviceContext);
	}
    	
	public List<Task> get(String interfaceId) throws Exception {		
		return service.get(interfaceId);
	}
    	
	public boolean schedule(Task task) throws Exception {		
		return service.schedule(task);
	}
	
	public boolean processResult(List<Task> results) {		
		return service.processResult(results);
	}	
	
	@ServiceRole(Role.TABLE)
	public void setService(TableDispatchService service) {
		this.service = service;
	}
}
